package cn.edu.ctbu.teachers.aop;

import cn.edu.ctbu.teachers.constant.REnum;
import cn.edu.ctbu.teachers.exception.RException;
import cn.edu.ctbu.teachers.util.RUtil;
import cn.edu.ctbu.teachers.vo.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    public R exceptionHandler(Exception e){
        if(e instanceof RuntimeException){
            RException rException=(RException) e;
            return RUtil.error(rException.getCode(), rException.getMessage());
        }
        return RUtil.error(REnum.UNKOWN_ERR);
    }
}
